<template>
  <view class="recruit-search">
    <view class="recruit-search__box">
      <text class="recruit-search__icon iconfont icon-search"></text>
      <input 
        class="recruit-search__input" 
        type="text" 
        :placeholder="placeholder" 
        confirm-type="search"
        :value="modelValue"
        @input="updateValue"
        @confirm="handleConfirm"
      />
      <text 
        v-if="modelValue" 
        class="recruit-search__clear iconfont icon-close"
        @click="handleClear"
      ></text>
    </view>
  </view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  modelValue: {
    type: String,
    default: ''
  },
  placeholder: {
    type: String,
    default: '搜索岗位名称、组织'
  }
});

const emit = defineEmits(['update:modelValue', 'search', 'clear']);

// 更新输入值
const updateValue = (e) => {
  emit('update:modelValue', e.detail.value);
};

// 处理搜索确认
const handleConfirm = () => {
  emit('search');
};

// 处理清除
const handleClear = () => {
  emit('update:modelValue', '');
  emit('clear');
};
</script>

<style lang="scss" scoped>
.recruit-search {
  padding: 12px 0;
  
  &__box {
    display: flex;
    align-items: center;
    height: 40px;
    background-color: #f0f2f5;
    border-radius: 20px;
    padding: 0 15px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  }
  
  &__icon {
    font-size: 18px;
    color: #999;
    margin-right: 8px;
  }
  
  &__input {
    flex: 1;
    height: 100%;
    font-size: 14px;
    color: #333;
  }
  
  &__clear {
    font-size: 16px;
    color: #999;
    padding: 4px;
  }
}
</style>
